<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <%--多附件上传css--%>
    <link rel="stylesheet" href="<s:url value="/assets/css/main.css"></s:url>"/>
</head>
<body class="no-skin">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<div class="modal fade" id="UrgeModel" tabindex="-1" role="dialog" aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">催办</h4></div>
            <div class="modal-body ">
                <div class="information">
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">姓名</label>
                        <div class="col-sm-9">
                            <input type="text" class="Modelname form-control" readonly>
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">电话</label>
                        <div class="col-sm-9">
                            <input type="text" class="Modelphone form-control" readonly>
                        </div>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <div class="col-sm-offset-2 col-sm-6">
                        <input type="checkbox" value="1" name="type">推送主要领导
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">常用语句</label>
                    <div class="col-sm-9">
                        <select class="form-control">
                            <option value="">点击选择</option>
                            <option>速度办理</option>
                            <option>及时办理</option>
                        </select>
                    </div>
                </div>
                <div class="form-group clearfix">
                    <label class="control-label col-sm-2 text-right">催办内容</label>
                    <div class="col-sm-9">
                        <textarea rows="3" class="form-control" style="resize: vertical;min-height: 100px"></textarea>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success UrgeSure" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="approval" tabindex="-1" role="dialog" aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">审批</h4></div>
            <div class="modal-body ">
                <div class="information1">
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">任务名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="mainName form-control" readonly value="">
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">内容</label>
                        <div class="col-sm-9">
                            <textarea type="text" class="Modelcontent form-control" readonly></textarea>
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <div class="col-sm-9 col-sm-offset-2">
                            <input type="radio" name="isApproval" value="2">通过
                            <input type="radio" name="isApproval" value="1">不通过
                        </div>
                    </div>
                    <div class="form-group clearfix">
                        <label class="control-label col-sm-2 text-right">审批意见</label>
                        <div class="col-sm-9">
                            <textarea rows="3" class="form-control content"></textarea>
                        </div>
                        <input type="hidden" class="taskMain" taskMain="${taskMain.sysId}">
                        <input type="hidden" class="sysId" value="">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success addApproval" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<%--修改--%>
<div class="modal fade" id="modify" tabindex="-1" role="dialog" aria-hidden="true"
     data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">修改</h4></div>
            <div class="modal-body " style="padding-left: 20px">
                <%--时限 类型--%>
                <%--                <div class="form-group clearfix">--%>
                <%--                    <label class="control-label col-sm-2 text-right">任务时限</label>--%>
                <%--                    <div class="col-sm-9">--%>
                <%--                        <input type="text" readonly lay-verify="date" placeholder="年-月-日" autocomplete="off" class="form-control date_picker" name="getTimeLimit" readonly>--%>
                <%--                    </div>--%>
                <%--                </div>--%>
                <div class="row">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">周期类型<font color="red">*</font></label>
                        <div class="col-sm-3">
                            <select name="timeType" id="thexiugName"
                                    onchange="chanceTheSelect(this.options[this.options.selectedIndex].value)">
                                <%--                <option value="">请选择</option>--%>
                                <option value="多时限">多时限</option>
                                <option value="单时限">单时限</option>
                                <option value="天">天</option>
                                <option value="周">周</option>
                                <option value="月">月</option>
                                <option value="季度">季度</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="row" style="margin-top: 20px">
                    <div class="form-group">
                        <label class="col-sm-2 control-label no-padding-right">时限<font color="red">*</font></label>
                        <div class="col-sm-5" id="shijianxuanxiangaaa">
                            <input type="text" name="cell4" value="${excelData.cell4}" class="form-control chance2_1_17"
                                   required>
                        </div>
                    </div>
                </div>
                <input type="hidden" name="sysId">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success confirmModify" data-dismiss="modal">确定</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>


<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <%--多附件上传的name和id--%>

    <input type="text" name="file" value="" hidden>
    <input type="text" name="fileName" value="" hidden>

    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <h3 class="text-center">我派发的任务</h3>
                <div id="taskMainId" style="display: none">
                    ${taskMainId}
                </div>
                <div class="form-group clearfix">
                    <h3 class="text-left">
                        任务名称:${taskMain.mainName}
                    </h3>
                </div>
                <div class="form-group clearfix">
                    <c:if test="${not empty taskMain.content}">
                        <h4 class="text-left">
                            任务内容:${taskMain.content}
                        </h4>
                    </c:if>
                </div>
                <div class="form-group clearfix">
                    <c:if test="${ not empty taskMain.fileNumber}">
                        <div class="pull-left">
                            <h3 class="text-left">
                                文号:${taskMain.fileNumber}
                            </h3>
                        </div>
                    </c:if>
                    <c:if test="${ not empty taskMain.overdueDept}">
                        <div class="pull-left">
                            <h3 class="text-left overdueDept">
                                督办单位:${overdueDept.deptName}
                            </h3>
                        </div>
                    </c:if>
                </div>
                <div class="form-group clearfix">
                    <c:if test="${not empty taskMain.files}">
                        <h4 class="col-sm-1">
                            附件:
                        </h4>
                        <div class="col-sm-9">
                                <%--<input type="text" disabled value="${taskMain.fileName}"><button class="btn-success btn-sm" FileSysId="${taskMain.file}" onclick="download(this)" style="margin-left: 10px">下载附件</button>--%>
                            <c:if test="${not empty taskMain.files}">
                                <c:forEach items="${taskMain.files}" var="fileMap">
                                    <div style="margin-bottom:15px;">
                                        <input style="width: 50%;" type="text" class="fileName" readonly
                                               title="${fileMap.fileName}"
                                               value="${fileMap.fileName}" onclick="copyFile(this)">
                                        <button class="btn btn-primary file" onclick="download(this)"
                                                FileSysId="${fileMap.file}">
                                            下载附件
                                        </button>
                                    </div>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty taskMain.files}">
                                <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control"
                                       readonly>
                            </c:if>
                        </div>
                    </c:if>
                </div>
                <div class="form-group clearfix">
                    <c:if test="${not empty taskMain.gJFile}">
                        <h4 class="col-sm-1">
                            攻坚附件:
                        </h4>
                        <div class="col-sm-9">
                                <%--<input type="text" disabled value="${taskMain.gJFileName}"><button class="btn-success btn-sm" FileSysId="${taskMain.gJFile}" onclick="download(this)" style="margin-left: 10px">下载附件</button>--%>
                            <c:if test="${not empty taskMain.gJFile}">
                                <c:forEach items="${taskMain.gJFile}" var="fileMap">
                                    <div style="margin-bottom:15px;">
                                        <input style="width: 50%;" type="text" class="fileName" readonly
                                               title="${fileMap.fileName}"
                                               value="${fileMap.fileName}" onclick="copyFile(this)">
                                        <button class="btn btn-primary file" onclick="download(this)"
                                                FileSysId="${fileMap.file}">
                                            下载附件
                                        </button>
                                    </div>
                                </c:forEach>
                            </c:if>
                            <c:if test="${empty taskMain.gJFile}">
                                <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control"
                                       readonly>
                            </c:if>
                        </div>
                    </c:if>
                </div>
                <%--<c:if test="${not empty taskMain.crucialUser}">
                    <c:choose>
                        &lt;%&ndash;读&ndash;%&gt;
                        <c:when test="${dept.sysId == '20190722100000000194'}">
                            <div class="form-group clearfix">
                                <div>
                                    <label class="col-sm-1 control-label">攻坚反馈:</label>
                                    <div class="col-sm-9">
                                        <textarea rows="1" class="form-control FeedbackContent"  placeholder="请输入内容" readonly style="resize: vertical;min-height: 50px;">${taskMain.mainResult}</textarea>
                                    </div>
                                </div>
                            </div>
                          &lt;%&ndash;  <div class="form-group clearfix">
                                <label class="control-label col-sm-1">反馈附件:</label>
                                <div class="col-sm-8">
                                    &lt;%&ndash;下载&ndash;%&gt;
                                        <input type="text" readonly value="${taskMain.mainResultFileName}">
                                        <button class="btn btn-primary" onclick="download(this)" FileSysId = "${taskMain.mainResultFile}">
                                            下载附件
                                        </button>
                                    &lt;%&ndash;上传&ndash;%&gt;
                                </div>
                            </div>&ndash;%&gt;
                            &lt;%&ndash;循环附件下载&ndash;%&gt;
                            <div class="form-group clearfix">
                                <label class="control-label col-sm-1">反馈附件:</label>
                                <div class="col-sm-8">
                                    <c:if test="${not empty taskMain.mainResultFile}">
                                        <c:forEach items="${taskMain.mainResultFile}" var="fileMap">
                                            <div style="margin-bottom:15px;">
                                                <input style="width: 50%;" type="text" class="fileName" readonly
                                                       title="${fileMap.fileName}"
                                                       value="${fileMap.fileName}" onclick="copyFile(this)">
                                                <button class="btn btn-primary file" onclick="download(this)"
                                                        FileSysId="${fileMap.file}">
                                                    下载附件
                                                </button>
                                            </div>
                                        </c:forEach>
                                    </c:if>
                                    <c:if test="${empty taskMain.mainResultFile}">
                                        <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                                    </c:if>
                                </div>
                            </div>
                            &lt;%&ndash;---以上为附件下载--&ndash;%&gt;
                        </c:when>
                        &lt;%&ndash;写&ndash;%&gt;
                        <c:otherwise>
                            <div class="form-group clearfix">
                                <div>
                                    <label class="col-sm-1 control-label">攻坚反馈:</label>
                                    <div class="col-sm-9">
                                        <textarea rows="1" class="form-control"  name="mainResult" placeholder="请输入内容" style="resize: vertical;min-height: 50px;">${taskMain.mainResult}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <label class="control-label col-sm-1">反馈附件:</label>
                                <div class="col-sm-8">
                                    <c:if test="${not empty taskMain.mainResultFile}">
                                        <c:forEach items="${taskMain.mainResultFile}" var="fileMap">
                                            <div style="margin-bottom:15px;">
                                                <input style="width: 50%;" type="text" class="fileName" readonly
                                                       title="${fileMap.fileName}"
                                                       value="${fileMap.fileName}" onclick="copyFile(this)">
                                                <button class="btn btn-primary file" onclick="download(this)"
                                                        FileSysId="${fileMap.file}">
                                                    下载附件
                                                </button>
                                            </div>
                                        </c:forEach>
                                    </c:if>
                                    <c:if test="${empty taskMain.mainResultFile}">
                                        <input style="width: 50%;" type="text" value="无附件" class=" col-sm-3 form-control" readonly>
                                    </c:if>
                                    &lt;%&ndash;<c:if test="${not empty taskMain.mainResultFile}">
                                        &lt;%&ndash;下载&ndash;%&gt;
                                        <input type="text" readonly value="${taskMain.mainResultFileName}">
                                        <button class="btn btn-info" FileSysId = "${taskMain.mainResultFile}"  onclick="download(this)"><span class="glyphicon glyphicon-save"></span>下载附件</button>
                                    </c:if>&ndash;%&gt;
                                        &lt;%&ndash;上传&ndash;%&gt;
                                    <div>
                                        <div id="uploader"></div>
                                       &lt;%&ndash; <div style="display: inline-block">
                                            <input type="file" class="fileBorder" id="fileuploadGJX">
                                        </div>
                                        <div style="display: inline-block">
                                            <button class="btn btn-info" onclick="uploadFile(this,'mainResultFile','mainResultFileName','fileuploadGJX')">
                                                <span class="glyphicon glyphicon-open"></span>上传附件
                                            </button>
                                        </div>&ndash;%&gt;
                                    </div>
                                    <button class="btn btn-success takefeedback">确认</button>
                                </div>
                            </div>
                        </c:otherwise>
                    </c:choose>
                </c:if>--%>
                <c:if test="${taskMain.categoryId == '20190919100000000001'}">
                    <c:choose>
                        <%--读--%>
                        <c:when test="${dept.deptRelation == '/01/'}">
                            <div class="form-group clearfix">
                                <div>
                                    <label class="col-sm-1 control-label">督办单位反馈:</label>
                                    <div class="col-sm-9">
                                        <textarea rows="1" class="form-control FeedbackContent"
                                                  placeholder="来自督办单位的反馈内容" readonly
                                                  style="resize: vertical;min-height: 50px;">${taskMain.mainResult}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <label class="control-label col-sm-1">反馈附件:</label>
                                <div class="col-sm-8">
                                        <%--    &lt;%&ndash;下载&ndash;%&gt;
                                        <input type="text" readonly value="${taskMain.mainResultFileName}">
                                        <button class="btn btn-info" onclick="download(this)" FileSysId = "${taskMain.mainResultFile}">
                                            下载附件
                                        </button>--%>
                                    <c:if test="${not empty taskMain.mainResultFile}">
                                        <c:forEach items="${taskMain.mainResultFile}" var="fileMap">
                                            <div style="margin-bottom:15px;">
                                                <input style="width: 50%;" type="text" class="fileName" readonly
                                                       title="${fileMap.fileName}"
                                                       value="${fileMap.fileName}" onclick="copyFile(this)">
                                                <button class="btn btn-primary file" onclick="download(this)"
                                                        FileSysId="${fileMap.file}">
                                                    下载附件
                                                </button>
                                            </div>
                                        </c:forEach>
                                    </c:if>
                                    <c:if test="${empty taskMain.mainResultFile}">
                                        <input style="width: 50%;" type="text" value="无附件"
                                               class=" col-sm-3 form-control" readonly>
                                    </c:if>
                                </div>
                            </div>
                            <c:if test="${taskMain.status != '4'}">
                                <div class="form-group clearfix">
                                    <label class="control-label col-sm-1">是否办结:</label>
                                    <div class="col-sm-8">
                                        <button onclick="taskTtatus(4)" class="btn-sm btn btn-success">办结</button>
                                        <button onclick="taskTtatus(5)" class="btn btn-sm btn-danger">退回重办</button>
                                    </div>
                                </div>
                            </c:if>
                            <c:if test="${taskMain.status == '4'}">
                                <div class="form-group clearfix">
                                    <label class="control-label col-sm-1">评价:</label>
                                    <div class="col-sm-2 yc">
                                        <select class="form-control hg" id="task-evaluations">
                                            <option value="1">好</option>
                                            <option value="2">中</option>
                                            <option value="2">差</option>
                                        </select>
                                    </div>
                                    <button onclick="evaluations()" class="btn-sm btn btn-success">确认评价</button>
                                </div>
                            </c:if>
                        </c:when>
                        <%--写--%>
                        <c:when test="${dept.sysId == taskMain.overdueDept and roleId == '02'}">
                            <div class="form-group clearfix">
                                <div>
                                    <label class="col-sm-1 control-label">单位重大反馈:</label>
                                    <div class="col-sm-9">
                                        <textarea rows="1" class="form-control" name="mainResult" placeholder="请输入内容"
                                                  style="resize: vertical;min-height: 50px;">${taskMain.mainResult}</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <label class="control-label col-sm-1">单位反馈附件:</label>
                                <div class="col-sm-8">
                                    <c:if test="${not empty taskMain.mainResultFile}">
                                        <c:forEach items="${taskMain.mainResultFile}" var="fileMap">
                                            <div style="margin-bottom:15px;">
                                                <input style="width: 50%;" type="text" class="fileName" readonly
                                                       title="${fileMap.fileName}"
                                                       value="${fileMap.fileName}" onclick="copyFile(this)">
                                                <button class="btn btn-primary file" onclick="download(this)"
                                                        FileSysId="${fileMap.file}">
                                                    下载附件
                                                </button>
                                            </div>
                                        </c:forEach>
                                    </c:if>
                                    <c:if test="${empty taskMain.mainResultFile}">
                                        <input style="width: 50%;" type="text" value="无附件"
                                               class=" col-sm-3 form-control" readonly>
                                    </c:if>
                                        <%--上传--%>
                                    <div>
                                        <div id="uploader"></div>
                                            <%--<div style="display: inline-block">--%>
                                            <%--<input type="file" class="fileBorder" id="fileuploadZDX">--%>
                                            <%--</div>--%>
                                            <%--<div style="display: inline-block">--%>
                                            <%--<button class="btn btn-info" onclick="uploadFile(this,'mainResultFile','mainResultFileName','fileuploadZDX')">--%>
                                            <%--<span class="glyphicon glyphicon-open"></span>上传附件--%>
                                            <%--</button>--%>
                                            <%--</div>--%>
                                    </div>
                                    <button class="btn btn-success takefeedbackWd">确认</button>
                                    <button class="btn btn-info " onclick="duchaRank()">排名</button>
                                </div>
                            </div>
                        </c:when>
                    </c:choose>
                </c:if>
                <div class="pull-right" style="margin-bottom: 20px;margin-top: 20px;margin-bottom: 10px;">
                    <%--<button class="btn-sm btn btn-success allTasks">全部任务</button>--%>
                    <c:if test="${taskMain.status == 0}">
                        <button class="btn-success btn btn-sm approval">审批</button>
                    </c:if>
                    <button class="btn-sm btn btn-success addTaskSub">新增子事项</button>
                    <button class="btn-sm btn btn-success addTaskUnitBtn">新增单位</button>
                   <%----%> <button class="btn-sm btn btn-success cancelAllTask">终止所有任务</button>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <h4 class="redTips">温馨提示：双击表格行或者点击"查看" 查看任务详情</h4>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

    <%@ include file="/WEB-INF/views/include/dialog.jsp" %>
</div><!-- /.main-container -->
</div>

<%--多选上传--%>
<script src="<s:url value="/assets/js/dist/easyUploader.jq.js"></s:url>"></script>
<!-- footer -->
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<%--用于没上传附件时不执行方法--%>
<input type="text" id="crucialUser" value="${taskMain.crucialUser}" hidden>
<input type="text" id="overdueDept" value="${taskMain.overdueDept}" hidden>

<input type="text" id="sysIds" value="${dept.sysId}" hidden>
<input type="text" id="categoryId" value="${taskMain.categoryId}" hidden>

<input type="text" id="deptRelations" value="${dept.deptRelation}" hidden>
<input type="text" id="roleIds" value="${roleId}" hidden>
<%--
<script>
    $(function () {
        var a = $("#crucialUser").val();
        var b = $("#sysIds").val();
        var c = $("#categoryId").val();
        var d = $("#deptRelations").val();
        var e = $("#overdueDept").val();
        var f = $("#roleIds").val();
        if (  ( a !== ""&& b !== "20190722100000000194") || (c === "20190919100000000001" && b === e && f === "02")) {
            &lt;%&ndash;多文件上传&ndash;%&gt;
            var fileStr = "";//id字符串拼接
            var fileNameStr = "";//文件名字符串拼接
            var uploader = easyUploader({
                id: "uploader",
                accept: '.jpg,.png,.doc,.docx,.pdf,.xls,.xlsx,.ppt,.pptx',
                action: '/filesUpload/uploadFiles',
                dataFormat: 'formData',
                maxCount: 10,//允许上传的个数
                maxSize: 2000,//允许上传最大的容量
                multiple: true,
                data: null,
                beforeUpload: function (file, data, args) {
                },
                onChange: function (fileList) {
                },
                onRemove: function (removedFiles, files) {
                    console.log('onRemove', removedFiles);
                },
                onSuccess: function (res) {
                    console.log('onSuccess', res);
                    if (res.data !== undefined && res.data[0] !== undefined) {
                        //拼接文件id 和 文件名
                        $("input[name='file']").val(fileStr += res.data[0].sysid + ",");
                        $("input[name='fileName']").val(fileNameStr += res.data[0].oldName + ",");

                    }
                },
                onError: function (err) {
                    console.log('onError', err);
                },
            });
        }
    })
</script>
--%>
<script type="text/javascript">
    // 基本路径
    var baseUrl = "<s:url value="/taskMain/query2/"></s:url>"

    // jqgrid的表格高度
    var height = 320;
    // jqgrid表格行头的中文
    var colNames = ['', '', '子事项', '责任单位', "单位类型", "任务时限", "分数", "任务轮次", "任务状态", "逾期天数", "操作"];

    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'taskSubId', index: 'taskSubId', width: 60, hidden: true, key: false},
        {name: 'taskSubName', index: 'taskSubName', width: 600, editable: true},
        {name: 'deptName', index: 'deptName', width: 150, editable: true, formatter: lastIndexFormatter},
        {name: 'unitType', index: 'unitType', width: 100, editable: true, formatter: categoryIdFormatter},
        {name: 'timeLimit', index: 'timeLimit', width: 100, editable: true,},
        {name: 'score', index: 'score', width: 100, editable: true,},
        {name: 'timeRound', index: 'timeRound', width: 100, editable: true, formatter: timeRoundFormatter},
        {name: 'type', index: 'type', width: 100, editable: true, formatter: typeFormatter},
        {name: 'overdueDay', index: 'overdueDay', width: 150, editable: true, formatter: overdueDayFormatter},
        {name: 'cz', width: 250, align: "center", formatter: feedbackBtnFormatter}
    ];

    /**
     * 按钮`
     */
    function feedbackBtnFormatter(value, grid, rows, state) {
        grid.colModel.title = false
        return "<div style='color: #049CE6;display: flex;justify-content: center'>" +
            "<div style='width: 60px;cursor: pointer;border-right:1px solid #049CE6;' title='反馈汇总' id='feedbackBtn1'>反馈汇总</div>" +
            "<div style='width: 40px;cursor: pointer' title='查看' id='feedbackBtn'>查看</div>" +
            "<div style='border-left:1px solid #049CE6;width: 40px;cursor: pointer'title='删除' class='delTask'>删除</div>" +
            "<div style='width: 40px;cursor: pointer;border-left:1px solid #049CE6;' class='urge' title='催办'>催办</div>" +
            "<div style='width: 40px;cursor: pointer;border-left:1px solid #049CE6;' class='modify' title='修改'>修改</div>" +
            "</div>";
    }

    /**
     * 任务时限轮数
     */
    function timeRoundFormatter(data) {
        return "第" + data + "轮"
    }

    /**
     * 任务类型格式化
     */
    function categoryIdFormatter(data) {
        switch (data) {
            case '1':
                return '牵头';
                break;
            case '2':
                return '协办';
                break;
            default:
                return '未知';
        }
    }

    function cycflagFormatter(data) {
        switch (data) {
            case 1:
                return '已终止，任务无效';
                break;
            case 0:
                return '任务有效';
                break;
            default:
                return '未知';
        }
    }

    function lastIndexFormatter(data) {
        return data.substring(0, data.length - 1)
    }

    /**
     * 任务状态格式化
     */
    function typeFormatter(data) {
        switch (data) {
            case '0':
                return '待签收';
                break;
            case '1':
                return '待反馈';
                break;
            case '2':
                return '已反馈';
                break;
            case '3':
                return '退回重办';
                break;
            case '4':
                return '完成';
                break;
            case '5':
                return '已签收';
                break;
                case "11":
                    return "未完成";
            default:
                return '未知';
        }
    }

    /**
     * 逾期天数
     */
    function overdueDayFormatter(data) {
        data = parseInt(data)
        if (data > 0) {
            return parseInt(data) + "天"
        } else {
            return ""
        }
    }

    /**
     * 附件格式化
     */
    function fileFormatter(data) {
        if (data == null || data == "") {
            return "无任务附件";
        } else {
            return '<input type="button" value="下载" onclick="downDetail(\'' + data + '\')" \n' +
                ' style="width: 100%; height: 32px;" class="btn-large btn-primary"/>';
        }
    }


    // jqgrid的具体执行方法
    var rowIds;
    var userList;
    var type;
    var taskSubId;
    jqgrid({
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        postData: {'taskMainId': $('#taskMainId').html().trim()},
        autoScroll: false,
        shrinkToFit: true,
        multiselect: false,
        rownumbers: true,
        subGrid: true,
        subGridRowExpanded:
            function (subgrid_id, row_id) {//子表格容器的id和需要展开子表格的行id

                bindSubGrid(subgrid_id, row_id);

            },
        onSelectRow: function (rowid, status) {
            rowIds = rowid
            //选择当前的行
            rowids = rowid
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
            var types = selectedRowValue.type;//获取任务状态
            //
            taskSubId = selectedRowValue.taskSubId;
            console.log(taskSubId);
        },
        ondblClickRow: function (rowid) {
            /**
             * 打开二级页面
             */
            var selectedRowValue = $("#gridTable").jqGrid('getRowData', rowid);
            // var taskSubId = selectedRowValue.taskSubId;
            //  window.parent.openapp("/taskMain/unitDetail/"+rowid,rowid,"任务详情");
            window.parent.openapp("/taskMain//mainunitDetail/" + rowid, rowid, "任务详情");
        },
        loadComplete: function (data) {
            var ids = $("#gridTable").jqGrid("getDataIDs");
            var rowDatas = $("#gridTable").jqGrid("getRowData");//获取所有行的数据
            for (var i = 0; i < rowDatas.length; i++) {
                if (data.rows[i].type == 2) {
                    $("#" + ids[i] + " td").css("background", "yellow"); //已反馈
                }
                ;
                if (data.rows[i].overdueDay) {
                    $("#" + ids[i] + " td").css("color", "red"); //逾期
                }
            }
        },
    });

    //点击开二级页面
    $(document).on("click", "#feedbackBtn1", function () {
        parent.openapp("/taskMain/collect/" + rowIds, rowIds, "反馈汇总");
    });
    $(document).on("click", "#feedbackBtn", function () {
        parent.openapp("/taskMain/unitDetail/" + rowIds, rowIds, "任务详情");
    });

    //    催办
    $(document).on("click", ".urge", function () {
        $.get("/taskMain/urgeModel/" + rowIds, function (data) {
            userList = data;
            var html = "";
            for (var i = 0; i < data.length; i++) {
                if (data[i].name == undefined) {
                    data[i]['name'] = ''
                }
                if (data[i].mobile == undefined) {
                    data[i]['mobile'] = ''
                }
                html += " <div class=\"form-group clearfix\">\n" +
                    "                        <label class=\"control-label col-sm-2 text-right\">姓名</label>\n" +
                    "                        <div class=\"col-sm-9\">\n" +
                    "                            <input type=\"text\" class=\"Modelname form-control\" readonly value='" + data[i].name + "'>\n" +
                    "                        </div>\n" +
                    "                    </div>\n" +
                    "                    <div class=\"form-group clearfix\">\n" +
                    "                        <label class=\"control-label col-sm-2 text-right\">电话</label>\n" +
                    "                        <div class=\"col-sm-9\">\n" +
                    "                            <input type=\"text\" class=\"Modelphone form-control\" readonly value='" + data[i].mobile + "'>\n" +
                    "                        </div>\n" +
                    "                    </div>"
            }

            $(".information").html(html);
        });
        $('#UrgeModel').modal('show'); //显示
    });

    $("#UrgeModel select").change(function () {
        $("#UrgeModel textarea").val($(this).val());
    })

    $(".UrgeSure").click(function () {
        failure(".UrgeSure", 1)
        type = $("input[name='type']:checked").val();
        if (!type) {
            type = 0;
        }
        var datas = {
            taskUnitId: rowIds,
            content: $("#UrgeModel textarea").val(),
            userList: userList,
            type: type
        }
        var jsonDatas = JSON.stringify(datas);
        $.ajax({
            url: '/taskMain/saveHasten/',
            type: 'POST',
            contentType: 'application/json; charset=UTF-8',
            async: false,
            dataType: 'json',
            data: jsonDatas,
            success: function (data) {
                if (data.code == "200") {
                    alert("催办成功");
                    $("#UrgeModel textarea").val("");
                    $("input[name='type']").removeAttr("checked");
                } else {
                    alert("催办失败");
                }
                failure(".UrgeSure", 0)
            }
        })
    })


    //审批
    $(document).on("click", ".approval", function () {
        var sysId = $(".taskMain").attr("taskMain")
        $('#approval').modal('show'); //显示
        $.get("/taskMain/approve/" + sysId, function (data) {
            $(".Modelcontent").val(data.content);
            $(".mainName").val(data.mainName);
            $(".sysId").val(data.sysId);

        })
    });
    $(".addApproval").click(function () {
        var datas = {
            status: $("[name='isApproval']:checked").val(),
            content: $(".information1 .content").val(),
            taskMainId: $(".sysId").val()
        }
        if (!datas.status) {
            return alert("请选择是否通过 ")
        }
        $.post("/taskMain/approve/", datas, function (data) {
            if (data.code == 200) {
                datas.status == 2 ? alert("通过审批") : alert("不通过审批")
                open(location, '_self').close();
            } else {
                alert("审批失败");
            }
        })
    })

    //攻坚反馈 takefeedback
    $(".takefeedback").click(function () {
        failure("takefeedback", 0)
        var datas = {
            mainResult: $("textarea[name='mainResult']").val(),
            mainResultFile: $("input[name=file]").val(),
            sysId: $(".taskMain").attr("taskMain"),
            mainResultFileName: $("input[name=fileName]").val()
        };
        $.ajax({
            url: "/taskMain/saveMainResult",
            type: "post",
            data: datas,
            success: function (data) {
                if (data.code == "200") {
                    alert(data.message);
                    setTimeout(function () {
                        open(location, '_self').close();
                    }, 50)
                } else if (data.code == "500") {
                    alert(data.message);
                }
                failure("takefeedback", 1)
            }
        })
    })


    //单位反馈
    $(".takefeedbackWd").click(function () {
        failure(".takefeedbackWd", 1)
        var datas = {
            mainResult: $("textarea[name='mainResult']").val(),
            mainResultFile: $("input[name=file]").val(),
            sysId: $(".taskMain").attr("taskMain"),
            mainResultFileName: $("input[name=fileName]").val()
        }
        /* var datas ={
             content:$("textarea[name='mainResult']").val() ,
             file:$("input[name=file]").val(),
             taskMainId:$(".taskMain").attr("taskMain"),
             fileName:$("input[name=fileName]").val()
         }*/
        $.ajax({
            // url:"/taskUnit/saveMainResult",
            url: "/taskUnit/saveDuBanBackInfo",
            type: "post",
            data: datas,
            success: function (data) {
                if (data.code == "200") {
                    alert(data.message);
                    setTimeout(function () {
                        open(location, '_self').close();
                    }, 50)
                } else if (data.code == "500") {
                    alert(data.message);
                }
                failure(".takefeedbackWd", 0)
            }
        })
    })

    //是否办结
    function taskTtatus(status) {
        var datas = {
            sysId: $(".taskMain").attr("taskMain"),
            status: status
        }
        $.ajax({
            url: "/taskMain/updateMainStatus/",
            type: "post",
            data: datas,
            success: function (data) {
                alert(data.message);
                setTimeout(function () {
                    open(location, '_self').close();
                }, 50)
            }
        })
    }

    /*修改任务*/
    $(document).on("click", ".date_picker", function () {
        laydate({
            elem: this,
            min: minDate(),
        });
    });
    $(document).on("click", ".modify", function () {
        $.get("/taskMain/getTaskUnit/" + rowIds, function (res) {
            $("input[name=thegetTimeLimit]").val(res.data.timeLimit)
            $("input[name=sysId]").val(res.data.sysId)
        })
        $("#modify").modal("show")
    })

    /*修改确认*/
    $(".confirmModify").click(function () {
        var datas = {
            subTimeLimit: $("input[name='thegetTimeLimit']").val() == undefined ? $('#thegetTimeLimitid option:selected').val() : $("input[name='thegetTimeLimit']").val(), //时限
            sysId: $("input[name='sysId']").val(),
            timeType: $('#thexiugName option:selected').val()
        }
        console.log(datas)
        $.post("/taskMain/editTaskUnit/", datas, function (data) {
            if (data.code == 200) {
                alert("修改成功")
                reload("#gridTable");//重载
            } else {
                alert("修改失败");
            }
        })
    })

    //删除子事项
    $(document).on("click", ".delTask", function () {
        if (confirm("是否删除")) {
            console.log("删除：" + taskSubId);
            $.get("/taskMain/deleteUnit/" + taskSubId, function (res) {
                if (res.code == "200") {
                    alert(res.message);
                    setTimeout(function () {
                        open(location, '_self').close();
                    }, 50)
                } else {
                    alert(res.message);
                }
            })
        }
    })
    //


    //新增子事项
    $(".addTaskSub").click(function () {
        var $taskMainSysId = $(".taskMain").attr("taskMain");
        loadDialog({
            dialogTitle: '新增子事项',
            dialogUrl: "/taskMain/addTaskSub/" + $taskMainSysId,
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
                '<button type="button" class="btn btn-default" onclick="removeLayDate()" data-dismiss="modal">关闭</button>'
        });
    })

    //新增子事项
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: "/taskMain/addTaskSub/",
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    //新增子事项单位
    $(".addTaskUnitBtn").click(function () {
        var $taskMainSysId = $(".taskMain").attr("taskMain");
        loadDialog({
            dialogTitle: '新增单位',
            dialogUrl: "/taskMain/addTaskUnit/" + $taskMainSysId,
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="createTask()">添加</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    })

    //新增子事项单位
    function createTask() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: "/taskMain/addTaskUnit/",
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }



    //终止所有任务
    $(".cancelAllTask").click(function () {

        console.log("终止任务");
        var taskMainSysId = $(".taskMain").attr("taskMain");


        $.ajax({
            url: "/taskMain/stopTask/"+taskMainSysId,
            type: "get",
            success: function (datas) {

                if(200==datas.code){
                    alert("已成功终止任务，不在生成周期性任务！将发送短信通知各单位本任务已经终止")
                }else {

                    alert("终止失败！请联系管理员")
                }
            }
        });




    })


    function minDate() {
        var now = new Date();
        return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + (now.getDate() + 1);
    }

    $(document).ready(function () {
        $(document).on("click", "#date_picker", function () {
            laydate({
                elem: "#date_picker",
                min: minDate(),
            });
        });
    })

    //bug 删除时间模态框
    function removeLayDate() {
        $("#laydate_box").remove()
    }




    //任务评价
    function evaluations() {

        var eval = $("#task-evaluations").val();
        console.log(eval)

        var datas = {
            evaluations: eval, //评价
            sysId: $(".taskMain").attr("taskMain")
        }
        console.log(datas)
        $.post("/taskMain/submitEval", datas, function (data) {
            if (data.code == 200) {
                alert("评价成功")
                reload("#gridTable");//重载
            } else {
                alert("修改失败");
            }
        })

    }

    function duchaRank() {
        var eval = $("#task-evaluations").val();//评价
        var sysId = $(".taskMain").attr("taskMain");
        parent.openapp("/taskMain/dubanfeedback?sysId=" + sysId + "&eval=" + eval, "接收单位")
    }



</script>

<script>
    function chanceTheSelect(data) {
        var xuanxianghtmlaaa = ""
        if (data == "多时限") {
            xuanxianghtmlaaa = "<div class='form-group'>" +
                "    <div class=\"col-sm-8 no-padding-left\">\n" +
                "        <input type=\"text\" placeholder=\"年-月-日\"  onblur=\"addTimeBtnDataaaa()\"     class=\"form-control  Zdate_picker date_picker danyanaaa\"   readonly>\n" +
                "    </div>\n" +
                "    <div class=\"col-sm-1 addTime\">\n" +
                "        <input type=\"button\" class=\"btn btn-sm btn-success\" onclick='addTimeBtn(this)' value=\"添加时限\">\n" +
                "        <input id=\"theshubmit\" type=\"hidden\" name=\"thegetTimeLimit\" class=\"form-control\" >\n" +
                "    </div>\n" +
                "    </div>"
        }
        if (data == "单时限") {
            xuanxianghtmlaaa = "<div class='form-group'>" +
                "    <div class=\"col-sm-8 no-padding-left\">\n" +
                "        <input type=\"text\" class=\"form-control Zdate_picker  date_picker transform\"  name=\"thegetTimeLimit\" readonly>\n" +
                "    </div>\n" +
                "    </div>"
        }
        if (data == "天") {
            xuanxianghtmlaaa = "<input type=\"number\" class=\"form-control\" min='0' name=\"thegetTimeLimit\"  placeholder=\"请输入天数\">"
        }
        if (data == "周") {
            xuanxianghtmlaaa = "      <select name=\"thegetTimeLimit\" id=\"thegetTimeLimitid\" class=\"form-control\" value=\"\" >\n" +
                "            <option value=\"1\">星期一</option>\n" +
                "            <option value=\"2\">星期二</option>\n" +
                "            <option value=\"3\">星期三</option>\n" +
                "            <option value=\"4\">星期四</option>\n" +
                "            <option value=\"5\">星期五</option>\n" +
                "            <option value=\"6\">星期六</option>\n" +
                "            <option value=\"7\">星期日</option>\n" +
                "        </select>"
        }
        if (data == "月") {
            xuanxianghtmlaaa = "<input type=\"text\" id=\"DBdate_pickeraaa\" value=\"\" readonly lay-verify=\"date\" name=\"thegetTimeLimit\" placeholder=\"日\" autocomplete=\"off\" class=\"layui-input form-control\">\n"
        }
        if (data == "季度") {
            xuanxianghtmlaaa = "<input type=\"text\" value = \"\"    readonly lay-verify=\"date\" placeholder=\"年-月-日\" name=\"thegetTimeLimit\" autocomplete=\"off\" class=\"layui-input form-control date_picker\">\n"
        }
        $("#shijianxuanxiangaaa").html(xuanxianghtmlaaa)
    }

    function addTimeBtn(e) {
        var html = " <div class=\"form-group\" style=\"margin-top: 10px\">" +
            "   <div class=\"col-sm-8 no-padding-left\">\n" +
            "       <input  type=\"text\" value=\"\" readonly lay-verify=\"date\" onblur=\"addTimeBtnDataaaa()\"    placeholder=\"年-月-日\" autocomplete=\"off\" class=\"layui-input form-control date_picker danyanaaa\">\n" +
            "</div>\n" +
            "    <div class=\"col-sm-1 addTime\">\n" +
            "        <input type=\"button\" class=\"btn btn-sm btn-danger removeTimeBtn\"  value=\"删除时限\">\n" +
            "    </div>" +
            "</div>"
        $(e).parent().parent().parent().append(html);
    }

    function addTimeBtnDataaaa() {
        setTimeout(function () {
            var value = [];
            $(".danyanaaa").each(function () {
                value.push($(this).val());
            });
            $('#theshubmit').attr('value', value.join(","))
        }, 200)
    }

    chanceTheSelect("多时限")
    $(document).on("click", "#DBdate_pickeraaa", function () {
        laydate({
            elem: "#DBdate_pickeraaa",
            format: 'YYYY-MM-DD',
            // min: minDate(),
            choose: function (data) {
                //将值赋值给input框
                var $checked = $("input[name='period2']:checked").val();
                data = data.substring(data.length - 2)
                $("#DBdate_pickeraaa").val(data);
            }
        });
    });

    $(document).on("click", ".removeTimeBtn", function () {
        $(this).parent().parent().remove();
    });


    function bindSubGrid(subgrid_id, collectLineId) {

        console.log(subgrid_id);
        console.log(collectLineId);
        var subgrid_table_id;
        subgrid_table_id = subgrid_id + "_t"; // (3)根据subgrid_id定义对应的子表格的table的id

        var subgrid_pager_id;
        subgrid_pager_id = subgrid_id + "_pgr" // (4)根据subgrid_id定义对应的子表格的pager的id

        // (5)动态添加子报表的table和pager
        $("#" + subgrid_id)
            .html(
                "<table id='" + subgrid_table_id + "' class='scroll'></table><div id='" + subgrid_pager_id + "' class='scroll'></div>");
        // (6)创建jqGrid对象
        $("#" + subgrid_table_id)
            .jqGrid(
                {
                    url: '/taskMain/gettaskunit?taskUnitId=' + collectLineId,// (7)子表格数据对应的url，注意传入的contact.id参数
                    datatype: "json",
                    colNames: ['id', '单位类型', '单位名称', '轮次', '任务状态', '周期状态','任务时限', '操作'],

                    colModel: [
                        {
                            name: "sysId",
                            index: "sysId",
                            width: 200,
                            key: true,
                            hidden: true
                        },

                        {
                            name: "unitType",
                            index: "unitType",
                            width: 200,
                            formatter: categoryIdFormatter,

                        }, {
                            name: "deptName",
                            index: "deptName",
                            // formatter : picFormatter,
                            width: 200
                        }, {
                            name: "timeRound",
                            index: "timeRound",
                            width: 200,

                        },

                        {name: 'type', index: 'type', width: 200, editable: true, formatter: typeFormatter},

                        {
                            name: "cycflag",
                            index: "cycflag",
                            formatter: cycflagFormatter,
                            width: 200,

                        },
                        {
                            name: "timeLimit",
                            index: "timeLimit",
                            width: 80,

                        },



                        {
                            name: "cz",
                            index: "cz",
                            width: 200,
                            formatter:function(value, grid, rows, state) {

                                return "<a onclick=stop('"+rows.sysId+"')>终止任务</a> | <a onclick=stopAndEnd('"+rows.sysId+"')>终止任务并办结</a> ";
                            }
                        }


                    ],
                    rowNum: 10,
                    rolList: [10, 20, 30],
                    pager: subgrid_pager_id,
                    mtype: "get",
                    viewrecord: true,
                    jsonReader: {
                        root: "content", //数据
                        page: "", //当前页
                        total: "totalPages", //  总页数
                        records: "totalElements",//从服务器端返回的记录数
                        repeatitems: false,
                        id: "id"
                    },
                    gridComplete: function () { // 数据加载完成后 添加 采购按钮

                    },
                });

    }


    function stop(jobId) {
        var url = "<s:url value="/taskMain/stopUnit/"/>" + jobId;
        $.post(url,	function(data){
                if(data.code == '200') {
                    showGritter('提示', '任务执行成功');//消息提示
                    reload("#gridTable");//重载
                } else {
                    showGritter('提示', '任务执行失败');//消息提示
                }
            }
        );
    }

    function stopAndEnd(jobId) {
        var url = "<s:url value="/taskMain/stopUnitAndEnd/"/>" + jobId;
        $.post(url,	function(data){
                if(data.code == '200') {
                    showGritter('提示', '任务执行成功');//消息提示
                    reload("#gridTable");//重载
                } else {
                    showGritter('提示', '任务执行失败');//消息提示
                }
            }
        );
    }



</script>
</body>
</html>